<template>
  <div class="road-div">
    <div class="header">
      <span class="title">{{ dataObject.tagName }}</span>
      <span class="close" @click="emit('close')"></span>
    </div>
   <img
      class="loveImg"
      v-if="!props.info.clused"
      @click="changeClused('1')"
      src="/images/new/tag/love.png"
    />
    <img class="loveImg"  @click="changeClused('0')" v-else src="/images/new/tag/loved.png" />
    <div class="tab-content">
      <span
        class="tab-btn"
        @click="changTab('1')"
        :class="{ active: currentTab == '1' }"
        >基本信息</span
      >
      <span
        class="tab-btn"
        @click="changTab('2')"
        :class="{ active: currentTab == '2' }"
        >道路监控</span
      >
      <span
        class="tab-btn"
        @click="changTab('3')"
        :class="{ active: currentTab == '3' }"
        >道路分析</span
      >
    </div>
    <div class="content-info">
      <!-- 基础信息 -->

      <div class="table-box" v-if="currentTab == '1'">
        <el-form class="formInfo" label-width="auto">
          <el-form-item label="起点位置">
            <span class="form-item">{{
              dataObject.baseInfo.baseInfo.beginPosition || "--"
            }}</span>
          </el-form-item>
          <el-form-item label="终点位置">
            <span class="form-item">{{
              dataObject.baseInfo.baseInfo.endPosition || "--"
            }}</span>
          </el-form-item>
          <el-form-item label="道路等级">
            <span class="form-item">{{
              dataObject.baseInfo.baseInfo.roadLevel || "--"
            }}</span>
          </el-form-item>
          <el-form-item label="监控数量">
            <span class="form-item">{{
              dataObject.baseInfo.baseInfo.monitorCnt || "--"
            }}</span>
          </el-form-item>
          <el-form-item label="车道数量">
            <span class="form-item">{{
              dataObject.baseInfo.baseInfo.laneCnt || "--"
            }}</span>
          </el-form-item>
          <el-form-item label="车道方向">
            <span class="form-item">{{
              dataObject.baseInfo.baseInfo.laneDirection || "--"
            }}</span>
          </el-form-item>
        </el-form>
      </div>
      <div class="map-box" v-if="currentTab == '1'">
        <!-- <mapBox></mapBox> -->
        <img
          style="width: 100%; height: 100%; margin-top: 20px"
          :src="dataObject.baseInfo.baseInfo.roadPic"
        />
      </div>

      <!--道路监控 -->
      <el-tabs v-model="videoTab" v-if="currentTab == '2'">
        <el-tab-pane
          :label="item.deviceName"
          v-for="item in dataObject.baseInfo.devices"
          :name="item.deviceName"
          :key="item.deviceName"
        >
          <div class="video-box">
            <onem ref="videoref" :vid="item.deviceId" />
          </div>
        </el-tab-pane>
      </el-tabs>
      <div class="header-box" v-if="currentTab == '2'">
        <span class="header-name">实时事件</span>
        <div>
          <el-select
            v-model="search.ly"
            placeholder="全部来源"
            style="width: 111px; margin-right: 12px"
          >
            <el-option
              v-for="item in lylist"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
          <el-select
            v-model="search.zt"
            placeholder="全部状态"
            style="width: 111px"
          >
            <el-option
              v-for="item in ztlist"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </div>
      </div>
      <div class="table-box" v-if="currentTab == '2'">
        <div class="header-t">
          <span class="ht">照片</span>
          <span class="ht">事件标题</span>
          <span class="ht">抓拍时间</span>
          <!-- <span class="ht">处置状态</span> -->
        </div>
        <div class="table-cell-box">
          <div class="cell-p" c v-for="item in eventList" :key="item">
            <span class="cell">
              <img class="img" :src="item.capturePic" />
            </span>
            <span class="cell" :title="item.desc"> {{item.desc}} </span>
            <span class="cell"> {{ item.captureTime }} </span>
            <!-- <span class="cell"> -- </span> -->
          </div>
        </div>
      </div>

      <!-- 道路分析 -->
      <div class="header-box" v-if="currentTab == '3'">
        <span class="header-name">当日分析</span>
      </div>
      <div class="table-box echarts-box" v-if="currentTab == '3'">
        <lineEcharts :options="optionsData" titleName="次"></lineEcharts>
      </div>
      <div class="table-box" style="height: 105px" v-if="currentTab == '3'">
        <div class="info-box">
          <p><span class="icon"></span>06:00-10:00，为高峰期</p>
          <p><span class="icon"></span>06:00-10:00，为高峰期</p>
          <p><span class="icon"></span>06:00-10:00，为高峰期</p>
        </div>
      </div>
      <div class="header-box" v-if="currentTab == '3'">
        <span class="header-name">年度分析</span>
      </div>
      <div class="table-box echarts-box" v-if="currentTab == '3'">
        <lineEcharts :options="optionsData" titleName="次"></lineEcharts>
      </div>
      <div
        class="table-box"
        style="height: 105px; overflow: auto"
        v-if="currentTab == '3'"
      >
        <div class="info-box">
          本年度，占道经营现象呈现出一定的季节性波动，夏季与节假日期间尤为突出。据统计，全年共记录占道经营事件35起。
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import mapBox from "./map.vue";
import lineEcharts from "./line.vue";
const emit = defineEmits(["close","changeClose"]);
const props = defineProps({
  info: Object,
  isd: {
    default: false,
    type: Boolean,
  },
});

const changeClused = (clused) => {
  emit('changeClose', clused);
};

let currentTab = ref("1");
const changTab = (tab) => {
  currentTab.value = tab;
};

let videoTab = ref("");
let videoref = ref();

let contentTab = ref("ryzpjl");

let optionsData = ref();

let lylist = ref([{ value: "1", label: "智能事件" }]);

let ztlist = ref([{ value: "1", label: "已处置" }]);
let search = ref({
  ly: "",
  zt: "",
});

watch(currentTab, () => {
  if (currentTab.value == "3") {
    optionsData.value = {
      xAxis: ["0-4", "4-8", "8-12", "12-16", "16-20", "20-24"],
      in: [120, 132, 101, 134, 90, 230],
      out: [132, 332, 301, 334, 190, 330],
    };
  }
});

let dataObject = ref({
  baseInfo: {
    devices: [
      // {
      //   deviceId: "123456",
      //   deviceName: "智能像头1",
      // },
      // {
      //   deviceId: "123456",
      //   deviceName: "智能像头2",
      // },
    ],
  },
});
const getData = () => {
  // videoTab.value = dataObject.value.baseInfo.devices[0].deviceName;
  // let res = {
  //   errorCode: "0",
  //   data: {
  //     tagInfo: {
  //       tagId: "1895098803678220299",
  //       tagName: "海宇道临开西路",
  //       deviceId: "1889981491715379232",
  //       categoryId: "1846861780832358401",
  //       categoryName: "地理信息",
  //       icon: "https://vp.bcdtech.cn:8787/new-port-file/dlbq.png",
  //       lightenIcon: "https://vp.bcdtech.cn:8787/new-port-file/dlbq.png",
  //       ptzZoompos: "1",
  //       ptzPanpos: "1",
  //       ptzTiltpos: "1",
  //       graphType: "point",
  //       graphData:
  //         '{"type":1,"data":[{"x":0.9423449612403101,"y":0.2423469387755102}]}',
  //       templateId: "WZ",
  //       templateTextdesc: null,
  //       templatePic: null,
  //       tempDeviceId: "1889981491715379210",
  //       deviceName: "海宇道临开西路右",
  //       originDeviceCode: "f55ff2738b6b4a628163ceb097c8d239",
  //       templateCapture:
  //         '{\n\t"baseInfo":{\n\t\t"beginPosition":"天津市滨海新区塘沽街道濒开里18号楼（海宇道）",\n\t\t"endPosition":"天津市滨海新区塘沽街道丰巢（海宇道）",\n\t\t"roadLevel":"城市次干道",\n\t\t"monitorCnt":5,\n\t\t"laneCnt":1,\n\t\t"laneDirection":"双向道",\n\t\t"roadPic":"https://vp.bcdtech.cn:8787/new-port-file/road海宇道.jpg"\n\t},\n\t"devices":[{\n\t\t"deviceName":"海宇道临开西路左","deviceId":"1889981491715379235"\n\t},{\n\t\t"deviceName":"海宇道临开西路右","deviceId":"1889981491715379210"\n\t}]\n}',
  //     },
  //     faceStats: null,
  //     vehicleStats: null,
  //     tempCapture: null,
  //   },
  //   message: "操作成功",
  // };
  // dataObject.value = {
  //   ...res.data.tagInfo,
  //   baseInfo: JSON.parse(res.data.tagInfo.templateCapture),
  // };
  // videoTab.value = dataObject.value.baseInfo.devices[0].deviceName;
  useApi
    .post("/dynamicview/ar/tagDetail", { tagId: props.info.tagId })
    .then((res) => {
      dataObject.value = {
        ...res.data.tagInfo,
        baseInfo: JSON.parse(res.data.tagInfo.templateCapture),
      };
      videoTab.value = dataObject.value.baseInfo.devices[0].deviceName;
    });
};

// 获取事件
let eventList = ref([]);
let typeSnap = ref("face");
const getEvent = (id) => {
  useApi
    .post("/dynamicview/ar/getcitymgrlistbydeviceid", {
      deviceId: id,
    })
    .then((res) => {
      // {
      //   "capturePic": "https://vp.bcdtech.cn:8787/picture?url=http://20.13.9.232:80/picture/Streaming/tracks/303/?name=ch00003_01010003140053933721600013103&size=13103",
      //   "gender": "女",
      //   "captureTime": "2025-03-05 15:25:04"
      // },
      //  {
      //   "capturePic": "https://vp.bcdtech.cn:8787/picture?url=http://20.13.7.221:80/picture/Streaming/tracks/3803/?name=ch00038_00010004650100477081600640316&size=640316",
      //   "plateNo": "津MTX823",
      //   "color": "red",
      //   "type": "vehicle",
      //   "captureTime": "2025-03-05 15:36:19"
      // },
      // if (res.data.faceCaptureList && res.data.faceCaptureList.length > 0) {
      //   eventList.value = res.data.faceCaptureList;
      //   typeSnap.value = "face";
      // } else if (
      //   res.data.vehicleCaptureList &&
      //   res.data.vehicleCaptureList.length > 0
      // ) {
      //   eventList.value = res.data.vehicleCaptureList;
      //   typeSnap.value = "vehicle";
      // }
      eventList.value = res.data.citymgrList;
    });
};

watch(videoTab, () => {
  try {
    let index = dataObject.value.baseInfo.devices.findIndex(
      (item) => item.deviceName == videoTab.value
    );
    if (index > -1) {
      getEvent(dataObject.value.baseInfo.devices[index].deviceId);
    }
    if (videoref.value) {
      videoref.value.resize();
    }
  } catch (e) {}
});

watch(
  () => props.info,
  (newval) => {
    if (newval.tagId) {
      getData();
    }
  },
  {
    deep: true,
    immediate: true,
  }
);

onMounted(() => {});
</script>

<style lang="scss">
.road-div {
  width: 503px;
  min-height: 720px;
  background: url("/images/new/tag/tagbg.png") no-repeat;
  background-size: 100% 100%;
  position: relative;
  padding-bottom: 30px;
  .loveImg {
    width: 40px;
    height: 40px;
    position: absolute;
    right: 40px;
    top: 75px;
    cursor: pointer;
     z-index: 999;
  }
  .header {
    width: 100%;
    height: 52.5px;
    position: relative;
    background: url("/images/new/tag/header.png") no-repeat;
    background-size: 100% 100%;
    .title {
      display: inline-block;
      height: 100%;
      padding-left: 25px;
      font-family: YouSheBiaoTiHei;
      font-size: 25px;
      color: #ffffff;
      line-height: 60px;
    }

    .close {
      width: 40px;
      height: 40px;
      position: absolute;
      right: 16px;
      top: 20.5px;
      line-height: 40px;
      text-align: center;
      color: #fff;
      font-size: 30px;
      cursor: pointer;
    }
  }
  .tab-content {
    margin: 23px 10px 10px 33px;
    width: 366px;
    height: 40px;
    background: url("/images/new/tag/tabbg.png") no-repeat;
    background-size: 100% 100%;
    display: flex;
    align-items: center;
    padding: 2px 4px;
    position: relative;
    .tab-btn {
      width: 115px;
      height: 100%;
      text-align: center;
      line-height: 36px;
      font-family: YouSheBiaoTiHei;
      font-size: 21px;
      color: #ffffff;
      cursor: pointer;
      &.active {
        background: url("/images/new/tag/tab.png") no-repeat;
        background-size: 100% 100%;
      }
    }
  }

  .content-info {
    padding: 0 30px;
    .table-box {
      width: 100%;
      background: url("/images/new/tag/tablebg.png") no-repeat;
      background-size: 100% 100%;
      .formInfo {
        width: 100%;
        padding: 20px;
        .el-form-item {
          margin-bottom: 0;
        }
        .el-form-item__label {
          font-family: PingFangSC, PingFang SC;
          font-size: 18px;
          color: #ffffff;
        }
        .form-item {
          font-family: PingFangSC, PingFang SC;
          font-size: 18px;
          color: #ffffff;
        }
      }
    }
    .map-box {
      width: 100%;
      height: 248px;
    }
  }
}
</style>

<style lang="scss">
.road-div {
  .video-box {
    width: 440px;
    height: 247.5px;
  }
  .el-select__wrapper {
    background: #067cc0;
    span {
      color: #ffffff !important;
    }
  }
  .el-tabs__item {
    font-family: YouSheBiaoTiHei;
    font-size: 21px;
    color: #ffffff;
    line-height: 29px;
    text-shadow: 0px 4px 4px rgba(0, 0, 0, 0.25);
    &.is-active {
    }
  }
  .el-tabs__nav-wrap:after {
    background: none;
  }
  .el-tabs__active-bar {
    background: #18e1ff;
  }
  .header-box {
    margin-top: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    .header-name {
      font-family: YouSheBiaoTiHei;
      font-size: 21px;
      color: #ffffff;
    }
  }
  .table-box {
    margin-top: 15px;
    width: 100%;
    background: url("/images/new/tag/tablebg.png") no-repeat;
    background-size: 100% 100%;
    .header-t {
      display: flex;
      align-items: center;
      width: 100%;
      height: 40px;
      background: url("/images/new/tag/headerbg.png") no-repeat;
      background-size: 100% 100%;
      color: #fff;
      .ht {
        height: 100%;
        font-family: PingFangSC, PingFang SC;
        font-weight: 600;
        font-size: 18px;
        color: #ffffff;
        line-height: 40px;
        margin: 16px 2px;
        &:nth-child(1) {
          padding-left: 20px;
        }
        &:nth-child(1) {
          width: 100px;
        }
        &:nth-child(2) {
          width: 100px;
        }
        &:nth-child(3) {
          flex: 1;
        }
        &:nth-child(4) {
          width: 100px;
        }
      }
    }
    .table-cell-box {
      width: 100%;
      height: 175px;
      overflow: auto;
      .cell-p {
        height: 50px;
        display: flex;
        align-items: center;
        overflow: hidden;
        margin: 8px 0;
        .cell {
          height: 100%;
          font-family: PingFangSC, PingFang SC;
          font-weight: 500;
          font-size: 18px;
          color: #ffffff;
          line-height: 50px;
          margin: 16px 2px;
          word-wrap: break-word; /* 长单词换行 */
          overflow-wrap: break-word; /* 推荐使用 */
          word-break: break-all; /* 强制在任意字符间换行 */
          white-space: normal; /* 默认换行行为 */
          // padding-left:12px;
          &:nth-child(1) {
            width: 100px;
            text-align: center;
            .img {
              width: 85px;
              height: 47.5px;
            }
          }
          &:nth-child(2) {
            width: 100px;
          }
          &:nth-child(3) {
            flex: 1;
            white-space: nowrap; /* 禁止换行 */
            overflow: hidden; /* 隐藏溢出内容 */
            text-overflow: ellipsis; /* 超出用省略号表示 */
          }
          &:nth-child(4) {
            width: 100px;
          }
        }
      }
    }
  }
  .echarts-box {
    height: 215px;
  }
  .info-box {
    padding: 13px;
    font-family: PingFangSC, PingFang SC;
    font-size: 18px;
    color: #ffffff;
    p {
      margin: 0;
      font-family: PingFangSC, PingFang SC;
      font-size: 18px;
      color: #ffffff;
      line-height: 27px;
      display: flex;
      align-items: center;
      .icon {
        border-radius: 50%;
        width: 9px;
        height: 9px;
        background: #88d4ff;
        margin-right: 15px;
      }
    }
  }
}
</style>